#ifndef __ENCRYPT_H__
#define __ENCRYPT_H__

#include <time.h>

#include "dict.h"

/*
 * encrypted_number_generate_register, generate encrypted register number string
 * hw_info: hardware info file path
 * serial: serial number
 * salt: salt for encryption
 */
char* encrypted_number_generate_register(const char* hw_info, const char* serial, const char* salt);

/*
 * encrypted_number_generate_kyhwid, generate encrypted hardware info string
 * hw_info: hardware info file path
 * serial: serial number
 * salt: salt for encryption
 */
char* encrypted_number_generate_kyhwid(const char* hw_info, const char* serial, const char* salt);

/*
 * activate_number_validate_normal, check if activation number is valid
 * hw_info: hardware info file path
 * serial: serial number
 * activate_number: activation number
 * return 1 if valid, or 0 if not
 */
int activate_number_validate_normal(const char* hw_info, const char* serial, const char* activate_number);

/*
 * activation_expire_date_normal, get date in form of struct tm from activation number
 * hw_info: hardware info file path
 * serial: serial number
 * activate_number: activation number
 * return date in form of struct tm 
 */
struct tm* activation_expire_date_normal(const char* hw_info, const char* serial, const char* activate_number);

/*
 * code_add_hyphen, add hyphen to code
 */
char* code_add_hyphen(const char* code);

/*
 * code_remove_hyphen, remove hyphen in code
 */
char* code_remove_hyphen(const char* code);

/*
 * activation_code_save, save activation code to file activation_file
 */
int activation_code_save(const char* activation_file, const char* activation_code);

/*
 * activation_code_load, load activation code from file activation_file
 */
char* activation_code_load(const char* activation_file);


// for ukey

/*
 * encrypted_number_generate_with_dict, generate encrypted string for ukey_serial
 */
char* encrypted_number_generate_with_dict(const char* register_code, const char* ukey_serial, const char* _salt, struct dict_set *dicts);

/*
 * register_code_is_valid, check if register code is valid
 * return 1 if valid, or 0 if not
 */
int register_code_is_valid(const char* register_code);

/*
 * activate_code_is_valid, check if activation code is valid
 * return 1 if valid, or 0 if not
 */
int activate_code_is_valid(const char* activate_code, struct dict_set* dicts);

/*
 * adjust_encrypted_date, adjust encrypted date
 */
char* adjust_encrypted_date(char* encrypted_date, const char* str, struct dict_set* dicts);

/*
 * activate_number_compare, compare default_date with real_date to see if real_date is valid 
 * return 1 if valid, or 0 if not
 */
int activate_number_compare(const char* default_date, const char* real_date);

/*
 * restore_encrypted_date, restore encrypted_date from str
 * return 0 if succeed, or -1 if not
 */
int restore_encrypted_date(char* encrypted_date, const char* str, struct dict_set* dicts);

/*
 * encrypt_hardware_info, encrypt hardware information
 * return NO_ERROR if succeeds, or return error number
 */
int encrypt_hardware_info(const char* hw_info, unsigned int in_size, unsigned char* out, unsigned int *out_size);

/*
 * decrypt_hardware_info, decrypt hardware information
 * return NO_ERROR if succeeds, or return error number
 */
int decrypt_hardware_info(const char* encrypted_info, unsigned int in_size, unsigned char* out, unsigned int *out_size);

#endif
